using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
namespace Circus.CodeEditor
{
	[Serializable]
    public class SortList<T> : List<T>
	{
		private int compareIndex;
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public int CompareIndex
		{
			get
			{
				return this.compareIndex;
			}
		}
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public new int Count
		{
			get
			{
				return base.Count;
			}
		}
		public bool NeedSort(IComparer<T> comparer)
		{
			T t = default(T);
			bool result;
			foreach (T current in this)
			{
				if (t != null && comparer.Compare(current, t) < 0)
				{
					result = true;
					return result;
				}
				t = current;
			}
			result = false;
			return result;
		}
		public bool FindExact(T obj, out int index, IComparer<T> comparer)
		{
			index = 0;
			bool result;
			if (comparer == null)
			{
				result = false;
			}
			else
			{
				int i = 0;
				int num = this.Count - 1;
				bool flag = false;
				while (i <= num)
				{
					int num2 = i + num >> 1;
					this.compareIndex = num2;
					int num3 = comparer.Compare(base[num2], obj);
					if (num3 < 0)
					{
						i = num2 + 1;
					}
					else
					{
						num = num2 - 1;
						if (num3 == 0)
						{
							flag = true;
							i = num2;
						}
					}
				}
				index = i;
				result = flag;
			}
			return result;
		}
		public bool FindFirst(T obj, out int index, IComparer<T> comparer)
		{
			int i = 0;
			int num = this.Count - 1;
			bool result = false;
			while (i <= num)
			{
				int num2 = i + num >> 1;
				this.compareIndex = num2;
				int num3 = comparer.Compare(base[num2], obj);
				if (num3 < 0)
				{
					i = num2 + 1;
				}
				else
				{
					num = num2 - 1;
					if (num3 == 0)
					{
						result = true;
					}
				}
			}
			index = i;
			return result;
		}
		public bool FindLast(T obj, out int index, IComparer<T> comparer)
		{
			int i = 0;
			int num = this.Count - 1;
			int num2 = 0;
			bool flag = false;
			while (i <= num)
			{
				int num3 = i + num >> 1;
				this.compareIndex = num3;
				int num4 = comparer.Compare(base[num3], obj);
				if (num4 > 0)
				{
					num = num3 - 1;
				}
				else
				{
					i = num3 + 1;
					if (num4 == 0)
					{
						num2 = num3;
						flag = true;
					}
				}
			}
			index = (flag ? num2 : i);
			return flag;
		}
		public bool FindExact(object obj, out int index, IComparer comparer)
		{
			index = 0;
			bool result;
			if (comparer == null)
			{
				result = false;
			}
			else
			{
				int i = 0;
				int num = this.Count - 1;
				bool flag = false;
				while (i <= num)
				{
					int num2 = i + num >> 1;
					this.compareIndex = num2;
					int num3 = comparer.Compare(base[num2], obj);
					if (num3 < 0)
					{
						i = num2 + 1;
					}
					else
					{
						num = num2 - 1;
						if (num3 == 0)
						{
							flag = true;
							i = num2;
						}
					}
				}
				index = i;
				result = flag;
			}
			return result;
		}
		public bool FindFirst(object obj, out int index, IComparer comparer)
		{
			int i = 0;
			int num = this.Count - 1;
			bool result = false;
			while (i <= num)
			{
				int num2 = i + num >> 1;
				this.compareIndex = num2;
				int num3 = comparer.Compare(base[num2], obj);
				if (num3 < 0)
				{
					i = num2 + 1;
				}
				else
				{
					num = num2 - 1;
					if (num3 == 0)
					{
						result = true;
					}
				}
			}
			index = i;
			return result;
		}
		public bool FindLast(object obj, out int index, IComparer comparer)
		{
			int i = 0;
			int num = this.Count - 1;
			int num2 = 0;
			bool flag = false;
			while (i <= num)
			{
				int num3 = i + num >> 1;
				this.compareIndex = num3;
				int num4 = comparer.Compare(base[num3], obj);
				if (num4 > 0)
				{
					num = num3 - 1;
				}
				else
				{
					i = num3 + 1;
					if (num4 == 0)
					{
						num2 = num3;
						flag = true;
					}
				}
			}
			index = (flag ? num2 : i);
			return flag;
		}
		public static bool InsideRange(Point pt, Rectangle rect)
		{
			return Range.InsideRange(pt, rect);
		}
		public static bool InsideRange(Point pt, Rectangle rect, bool checkMaxInt)
		{
			return Range.InsideRange(pt, rect, checkMaxInt);
		}
		public static bool UpdatePos(int x, int y, int deltaX, int deltaY, ref Point pt, bool endPos)
		{
			return Range.UpdatePos(x, y, deltaX, deltaY, ref pt, endPos);
		}
		public static bool UpdatePos(int x, int y, int deltaX, int deltaY, ref int ch, ref int ln, bool endPos)
		{
			return Range.UpdatePos(x, y, deltaX, deltaY, ref ch, ref ln, endPos);
		}
		
	}
}
